include Math

class Degree
  attr_accessor :sec_value
  
  def initialize(h,m,s)
    @sec_value = s+60*(m + 60*h)
  end
  
  def to_s
    "#{degrees} #{minutes} #{seconds}"
  end  
  
  def to_f
    @sec_value.to_f
  end
  
  def to_rad
    @sec_value*PI/(3600*180)
  end
  
  def degrees
    @sec_value.to_i / 3600
  end
  
  def minutes
    (@sec_value.to_i-3600*degrees) / 60
  end
  
  def seconds
    @sec_value - 3600*degrees - 60*minutes
  end
  
  def degretize
    Degree.new(0,0,15*sec_value)
  end
  
  def belongs_to_domain?(degree,domain_size)
    (sec_value - degree.sec_value).abs < domain_size
  end
  
  def +(degree)
    Degree.new(0,0,sec_value+degree.sec_value)
  end
end
